package com.danieldura.highrise.data
{
	import com.adobe.utils.DateUtil;
	
	public class Task
	{
		public static const SUBJECT_PARTY:String = "Party";
		public static const SUBJECT_CASE:String = "Kase";		
		
		public static const FRAME_TODAY:String = "today";
		public static const FRAME_TOMORROW:String = "tomorrow";
		public static const FRAME_THISWEEK:String = "this_week";
		public static const FRAME_NEXTWEEK:String = "next_week";
		public static const FRAME_LATER:String = "later";
		
		public var id:int;
		public var authorId:int;
		public var ownerId:int;
		public var recordingId:int;
		public var subjectId:int;
		public var subjectType:String;
		public var body:String;
		public var frame:String;
		public var alertAt:Date;
		public var doneAt:Date;
		public var categoryId:int;
		public var createdAt:Date;
		public var updatedAt:Date;
		
		public function parse( data:XML ):void
		{
			id = data.id;
			authorId = data["author-id"];
			ownerId = data["owner-id"];
			recordingId = data["recording-id"];
			subjectId = data["subject-id"];
			subjectType = data["subject-type"];
			body = data.body;
			frame = data.frame;
			alertAt = DateUtil.parseW3CDTF( data["alert-at"] );
			doneAt = DateUtil.parseW3CDTF( data["done-at"] );
			categoryId = data["category-id"];
			createdAt = DateUtil.parseW3CDTF( data["created-at"] );
			updatedAt = DateUtil.parseW3CDTF( data["updated-at"] );
		}
		
		public function toXML():XML
		{
			var data:XML = new XML( <task /> );
			data.id = id;
			data["recording-id"] = recordingId;
			data["subject-id"] = subjectId;
			data["subject-type"] = subjectType;
			data.body = body;
			data.frame = frame;
			data["alert-at"] = DateUtil.toW3CDTF( alertAt );
			data["category-id"] = categoryId;
			return data;
		}
		
		public function toXMLString():String
		{
			return toXML().toXMLString();
		}
				
	}
}

/*
<task>
  <id type="integer">1</id>
  <author-id type="integer">1</author-id>
  <owner-id type="integer">1</owner-id>
  <recording-id type="integer"></recording-id>
  <subject-id type="integer"></subject-id>
  <subject-type></subject-type>
  <body>Remember to do something important</body>
  <frame>#{ today || tomorrow || this_week || next_week || later }</frame>
  <alert-at type="datetime"></alert-at>
  <done-at type="datetime"></done-at>
  <category-id type="integer"></category-id>
  <created-at type="datetime"></created-at>
  <updated-at type="datetime">2007-04-26T02:04:03Z</updated-at>
</task>
*/